package com.shiwaixiangcun.customer.adapter;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.SectionEntity;
import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.entity.MidwayLine;

import java.util.List;

/**
 * @author Administrator
 * @date 2017/12/8
 */

public class AdapterTicket extends BaseSectionQuickAdapter<AdapterTicket.TicketSection, BaseViewHolder> {


    public AdapterTicket(List<TicketSection> data) {
        super(R.layout.item_layout_ticket, R.layout.item_layout_ticket_header, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, TicketSection item) {
        if (item.isHeader) {
            helper.setText(R.id.tv_date, item.strHeader);
        }

    }

    @Override
    protected void convert(BaseViewHolder helper, TicketSection item) {
        MidwayLine dataBean = item.dataBean;
        helper.setText(R.id.tv_time, dataBean.getGoTime());
        helper.setText(R.id.tv_origin, dataBean.getStartSiteName());
        helper.setText(R.id.tv_destination, dataBean.getEndSiteName());
        helper.setText(R.id.tv_travle_time, dataBean.getTime());
        helper.setText(R.id.tv_house_price, "￥" + dataBean.getPrice());
        helper.setText(R.id.tv_remainder, "剩余" + dataBean.getRemainTicket() + "张");

    }

    public void addData(List<TicketSection> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void clearData() {
        this.mData.clear();
        notifyDataSetChanged();
    }

    public static final class TicketSection extends SectionEntity<MidwayLine> {

        private String strHeader;
        private MidwayLine dataBean;

        public TicketSection(boolean isHeader, String header) {
            super(isHeader, header);
            this.isHeader = true;
            strHeader = header;

        }

        public TicketSection(MidwayLine midwayLine) {
            super(midwayLine);
            this.dataBean = midwayLine;
        }
    }
}
